#include "FEnergy.h"

FEnergy::FEnergy(PotFitter* fit)
{
	this->minimaxi = ObjectiveFunction::MINIMIZE;
	this->fit = fit;
	nDim = fit->getNParam();
	
	double* lb = fit->getLBound();
	double* ub = fit->getUBound();

	for(int i=0; i<nDim; i++)
	{
		lowerBounds.push_back(lb[i]);
		upperBounds.push_back(ub[i]);
	}

	initialize();
}

FEnergy::~FEnergy()
{
}

double FEnergy::evaluate_( vector<double>& x )
{
	ObjectiveFunction::evaluate_( x );
	
	double* _x = new double[nDim];

	for(int i=0; i<nDim; i++) _x[i] = x[i];

	double fitness = fit->evaluate(_x);

	return fitness;
}

vector<double> FEnergy::gradient_( vector<double>& x )
{
	return finiteDifference(x);
}
